<?php
 /*
   * Author : 1. Novi Setiani
   *          
   * Last edited : 4 Mei 2011
 */

include 'page/abstractPage.php';

class login extends AbstractPage {

    var $action;

    public function __construct() {
        parent::__construct();
        $this->load->library('session');
    }

    public function in() {
        $this->action = 'in';		
        $this->index();
    }

    public function check() {
        $userID = $this->input->post('username');
        $password = $this->input->post('password');

        $this->load->model('Pengguna', 'pengguna');
        $pengguna = $this->pengguna->getByUsername($userID);
        if (!empty($pengguna) && $pengguna['password'] == $password) {
            $this->session->set_userdata(array('pengguna' => array('userID' => $pengguna['userID'], 'role' => $this->pengguna->getRoleName($userID))));
            redirect('/');
        } else {
            //$this->data = array ('pesan' => 'Invalid username atau password');
			$this->session->set_flashdata('error_msg','Username atau password tidak valid');
            redirect('/login/in');
        }
    }

    public function out() {
        $this->session->sess_destroy();
        redirect('/login/in');
    }

    function _buildcontent() {
        //if($this->action =='in'){
		$data = array('error_msg'=>$this->session->flashdata('error_msg'));
        $this->load->view('login/index', $data);
    }

}

?>